package com.ymatou.iapi.couponmanage.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.ymatou.iapi.couponmanage.parameter.BatchInfo;
import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.parameter.changeUseConditionBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.changeUseConditionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponusecondition;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponuseconditionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.DataUtil.Json;
/**
*获取套券中的子批次信息(支持批量)
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_changeUseCondition{
	private static changeUseConditionBean bean;
	private static changeUseConditionCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改批次使用条件");
	}

	@Before
	public void caseUp() {
		bean=new changeUseConditionBean();
		call=new changeUseConditionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_001() {
		Logger.start(true,"修改批次使用条件-普通优惠券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			verifyReturn(1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_010() {
		Logger.start(true,"修改批次使用条件-套券");
		try {
			CreateBagCall createBagCall=setcouponBagPlatform();
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			verifyReturn(1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_002() {
		Logger.start(true,"修改批次使用条件-验证商品限制类型错误");
			try {
				CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
				CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
				List<Integer> sellerIds = new ArrayList<Integer>();
				sellerIds.add(111);
				createCouponBean.setSellerIds(sellerIds);
				CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
				
				Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
				List<String> lst1=new ArrayList();
				lst1.add("345");
				lst1.add("678");
				map.put(10,lst1 );
				
				couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
				bean.setBatchId(batch.getBatchId());
				bean.setConditionType(1);
				bean.setName("testName");
				bean.setDes("testDes");
				bean.setMemo("testMemo");
				bean.setconditionValueMap(map);
				
				call.setData(bean);
				call.callService();	
				
				Logger.verifyEquals(true, call.getMessage().contains("商品限制条件错误,请传入指定的商品限制条件"), "验证返回的message");
				Logger.verifyEquals("2", call.getCode1(), "验证返回的message");
			} catch (Exception e) {
				Logger.fail(e);
			}		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_003() {
		Logger.start(true,"修改批次使用条件-验证通用-使用条件无需调整");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("不允许修改商品限制条件类型"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_014() {
		Logger.start(true,"修改批次使用条件-验证通用-修改优惠券名称，描述备注");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(0);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			verifyReturn(1);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_004() {
		Logger.start(true,"修改批次使用条件-验证商品限制条件类型数量不正确");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> countrys = new ArrayList<Integer>();
			countrys.add(5);
			createCouponBean.setCountrys(countrys);
			
			List<Integer> categories = new ArrayList<Integer>();
			categories.add(4);
			createCouponBean.setCategories(categories);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("55");
			map.put(5,lst1 );
			
			List<String> lst2=new ArrayList();
			lst2.add("44");
			map.put(4,lst2 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(7);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			verifyReturn(4);
			verifyReturn(5);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_005() {
		Logger.start(true,"修改批次使用条件-验证商品限制条件错误,请传入指定的商品限制条件");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(3);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("商品限制条件错误,请传入指定的商品限制条件"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的errorcode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_006() {
		Logger.start(true,"修改批次使用条件-验证批次不存在");
		try {
			
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId()+1111);
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("批次不存在"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的errorcode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_007() {
		Logger.start(true,"修改批次使用条件-验证数据库ConditionType与修改的ConditionType不一致-不允许修改商品限制条件类型");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(3);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("商品限制条件错误,请传入指定的商品限制条件"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的errorcode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_008() {
		Logger.start(true,"修改批次使用条件-验证ConditionType为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId()+1111);
			//bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("使用条件无需调整"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的errorcode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_009() {
		Logger.start(true,"修改批次使用条件-验证conditionValueMap为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId()+1111);
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(null);
			
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals(true, call.getMessage().contains("请传入商品限制条件"), "验证返回的message");
			Logger.verifyEquals("2", call.getCode1(), "验证返回的errorcode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_011() {
		Logger.start(true,"修改批次使用条件-普通优惠券-优惠券名字为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			//bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals(true, call.getMessage().contains("name must"), "验证返回的message");
			Logger.verifyEquals("1", call.getCode1(), "验证返回的errorcode");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_012() {
		Logger.start(true,"修改批次使用条件-普通优惠券-优惠券备注为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			bean.setName("testName");
			bean.setDes("testDes");
			//bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals(true, call.getMessage().contains("memo must"), "验证返回的message");
			Logger.verifyEquals("1", call.getCode1(), "验证返回的errorcode");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_013() {
		Logger.start(true,"修改批次使用条件-普通优惠券-优惠券描述为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<Integer> sellerIds = new ArrayList<Integer>();
			sellerIds.add(111);
			createCouponBean.setSellerIds(sellerIds);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(1,lst1 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(1);
			bean.setName("testName");
			//bean.setDes("testDes");
		    bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals(true, call.getMessage().contains("des must"), "验证返回的message");
			Logger.verifyEquals("1", call.getCode1(), "验证返回的errorcode");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_015() {
		Logger.start(true,"修改批次使用条件-普通优惠券-迭代JIRACONN-24285");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			
			
			List<Integer> aids = new ArrayList<Integer>();
			aids.add(111);
			createCouponBean.setActivityIds(aids);
			
			List<Integer> bids = new ArrayList<Integer>();
			bids.add(1);
			createCouponBean.setBrands(bids);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=Lists.newArrayList();
			lst1.add("345");
			lst1.add("678");
			map.put(3,lst1 );
			
			List<String> lst2=Lists.newArrayList();
			lst2.add("1");
			lst2.add("2");
			map.put(6,lst2 );
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(10);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			//verifyReturn(10);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_changeUseCondition_016() {
		Logger.start(true,"修改批次使用条件-套券，迭代--JIRACONN-24285");
		try {
			Logger.comment("########创建套券开始###########");
			CreateBagBean CreateBagBean = new CreateBagBean();
			CreateBagBean.setName("自动化创建套券领取优惠券");
			CreateBagBean.setDescription("自动化测试创建套券领取优惠券描述");
			CreateBagBean.setOperatorId(222222);
			CreateBagBean.setApplyUser("自动化user111");
			CreateBagBean.setApplyMemo("自动化测试创建套券领取优惠券申请理由");
			CreateBagBean.setEffectiveType(0);
			CreateBagBean.setEffectiveValidType(0);
			CreateBagBean.setEffectiveDays(0);
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();
			Date dAfter = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			Calendar calendar2 = Calendar.getInstance(); // 得到日历
			calendar2.setTime(dNow);// 把当前时间赋给日历
			calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
			dAfter = calendar2.getTime(); // 得到前一天的时间

			CreateBagBean.setValidStart(dBefore);
			CreateBagBean.setValidEnd(dAfter);
			CreateBagBean.setAcquireStartTime(dBefore);
			CreateBagBean.setAcquireEndTime(dAfter);
			// 获取优惠券方式(1:领取(默认) 2:兑换)
			CreateBagBean.setAcquireMethod(1);
			CreateBagBean.setTotalNum(10);
			CreateBagBean.setReceiveTimesPerUser(1);
			CreateBagBean.setReceiveUserType(0);
			List<Integer> usePlatforms = new ArrayList<Integer>();
			CreateBagBean.setUsePlatformIds(usePlatforms);
			CreateBagBean.setApplyDepartment(1);
			String impresetInvoiceId = EnvSetup.getData("ImpresetInvoiceId");
			CreateBagBean.setImpresetInvoiceId(impresetInvoiceId);
			
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			ActivityIds.add(1);
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			Brands.add(2);
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			BatchInfos.add(info);
			CreateBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = new CreateBagCall();
			createBagCall.setData(false, CreateBagBean);
			createBagCall.callService();
			Logger.comment("########创建套券结束###########");
			
			Map<Integer, List<String>> map=new HashMap<Integer, List<String>>();
			List<String> lst1=new ArrayList();
			lst1.add("123");
			lst1.add("456");
			map.put(3,lst1 );
			
			List<String> lst2=new ArrayList();
			lst2.add("1");
			lst2.add("2");
			map.put(6,lst2 );
			
			couponbatch batch=new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
			bean.setBatchId(batch.getBatchId());
			bean.setConditionType(10);
			bean.setName("testName");
			bean.setDes("testDes");
			bean.setMemo("testMemo");
			bean.setconditionValueMap(map);
			
			call.setData(bean);
			call.callService();		
			verifyReturn(3);
			verifyReturn(6);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyReturn(int conditionType)
	{
		Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回的message");
		Logger.verifyEquals("0", call.getCode1(), "验证返回的errorcode");
		//验证数据库
		List<couponusecondition> couponuseconditions=new couponuseconditionWapper().selectByConditionTypeAndBatchId(bean.getBatchId(),conditionType);
		couponbatch batch=new couponbatchWapper().selectByPrimaryKey(bean.getBatchId());
		Logger.verifyEquals(bean.getConditionType(), batch.getUseConditionType(), "验证数据库couponbatch表中的ConditionType字段");
		for(int i=0;i<couponuseconditions.size();i++)
		{
			couponusecondition c=couponuseconditions.get(i);
			String value=bean.getconditionValueMap().get(conditionType).get(i);
			Logger.verifyEquals(c.getConditionType(), conditionType, "验证数据库couponusecondition表中的ConditionType字段");
			Logger.verifyEquals(c.getConditionValue(), value, "验证数据库couponusecondition表中的ConditionValue字段");
		}
	}
	private CreateBagCall setcouponBagPlatform() throws ClientProtocolException, IOException
	{
		CreateBagBean CreateBagBean = new CreateBagBean();
		CreateBagBean.setName("自动化创建套券领取优惠券");
		CreateBagBean.setDescription("自动化测试创建套券领取优惠券描述");
		CreateBagBean.setOperatorId(222222);
		CreateBagBean.setApplyUser("自动化user111");
		CreateBagBean.setApplyMemo("自动化测试创建套券领取优惠券申请理由");
		CreateBagBean.setEffectiveType(0);
		CreateBagBean.setEffectiveValidType(0);
		CreateBagBean.setEffectiveDays(0);
		
		Date dNow = new Date(); // 当前时间
		Date dBefore = new Date();
		Date dAfter = new Date();

		Calendar calendar1 = Calendar.getInstance(); // 得到日历
		calendar1.setTime(dNow);// 把当前时间赋给日历
		calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
		dBefore = calendar1.getTime(); // 得到前一天的时间

		Calendar calendar2 = Calendar.getInstance(); // 得到日历
		calendar2.setTime(dNow);// 把当前时间赋给日历
		calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
		dAfter = calendar2.getTime(); // 得到前一天的时间

		CreateBagBean.setValidStart(dBefore);
		CreateBagBean.setValidEnd(dAfter);
		CreateBagBean.setAcquireStartTime(dBefore);
		CreateBagBean.setAcquireEndTime(dAfter);
		// 获取优惠券方式(1:领取(默认) 2:兑换)
		CreateBagBean.setAcquireMethod(1);
		CreateBagBean.setTotalNum(10);
		CreateBagBean.setReceiveTimesPerUser(1);
		CreateBagBean.setReceiveUserType(0);
		List<Integer> usePlatforms = new ArrayList<Integer>();
		/*
		 * usePlatforms.add(1); usePlatforms.add(2); usePlatforms.add(3);
		 */
		CreateBagBean.setUsePlatformIds(usePlatforms);
		CreateBagBean.setApplyDepartment(1);
		String impresetInvoiceId = EnvSetup.getData("ImpresetInvoiceId");
		CreateBagBean.setImpresetInvoiceId(impresetInvoiceId);
		
		List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
		BatchInfo info=new BatchInfo();
		info.setCouponName("自动化创建套券优惠券名称-子套券");
		info.setCouponDes("自动化创建套券优惠券描述-子套券");
		info.setApplyMemo("自动化创建申请理由-子套券");
		info.setOrderMinAmount(new BigDecimal(2));
		info.setDeductionMaxAmount(new BigDecimal(1));
		List<String> productIds = new ArrayList<String>();
		info.setProductIds(productIds);
		List<Integer> SellerIds = new ArrayList<Integer>();
		SellerIds.add(11);
		info.setSellerIds(SellerIds);
		List<Integer> ActivityIds = new ArrayList<Integer>();
		info.setActivityIds(ActivityIds);
		List<Integer> Brands = new ArrayList<Integer>();
		info.setBrands(Brands);
		List<Integer> Countrys = new ArrayList<Integer>();
		info.setCountrys(Countrys);
		List<Integer> Categories = new ArrayList<Integer>();
		info.setCategories(Categories);
		info.setLimitPspProduct(false);
		BatchInfos.add(info);
		CreateBagBean.setBatchInfos(BatchInfos);	
		CreateBagCall createBagCall = new CreateBagCall();
		createBagCall.setData(false, CreateBagBean);
		createBagCall.callService();
		return createBagCall;
	}
}